let api = require('../../../api/api.js')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    display: "none"
  },
  urlIndex: function() {
    wx.switchTab({
      url: '/pages/index/index'
    })
  },
  hideview: function() {
    this.setData({
      display: "none"
    })
  },
  quxiaobg: function() {
    this.setData({
      display: "block"
    })
  },
  quxiao: function(e) {
    console.log(e)
    var id = e.currentTarget.id
    var data = {
      order_sn: id
    }
    api.order_cancel(data, res => {
      console.log(res)
      // this.setData({
      //   title: res.data.result
      // })
      if (res.data.result == 1){
        wx.navigateBack({
          detla:1
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let data = {
      order_sn: options.id
    }
    wx.showLoading({
      title: '加载中',
    })
    this.contentData(data)
  },
  contentData(data) {
    api.orderConten(data, (res) => {
      console.log(res)
      this.setData({
        contentData: res.data.result
      })
    })
    wx.hideLoading();
  },
  phone: function(e) {
    console.log(e)
    let phon = e.currentTarget.id
    console.log(phon)
    wx.makePhoneCall({
      phoneNumber: phon,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  Loca(e) {
    let id = e.currentTarget.id
    wx.navigateTo({
      url: `/pages/buy/site/site?id=${id}`,
    })
  },
  okData(e) {
    let id = e.currentTarget.id
    let data = {
      order_sn: e.currentTarget.id
    }
    api.confirmarrival(data, (res) => {

      this.contentData(data)
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  goPay(e) {
    console.log(e)
    let id = e.currentTarget.id
    let data = {
      order_sn: id
    }
    let that = this
    api.payGo(data, (res) => {
      wx.requestPayment({
        'timeStamp': res.data.result.timeStamp,
        'nonceStr': res.data.result.nonceStr,
        'package': res.data.result.package,
        'signType': 'MD5',
        'paySign': res.data.result.paySign,
        'success': function(res) {
          console.log(res, '支付成功')
          that.onLoad();
        },
        'fail': function(res) {
          wx.showToast({
            title: '支付失败',
            icon: "none"
          })
        },
        'complete': function(res) {}
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },


})